//package com.yunxin.admin.system.api.core.channel;
//
//import com.yunxin.admin.system.infra.common.constant.SecurityConstants;
//import com.yunxin.admin.system.infra.common.enums.AdminResultCode;
//import com.yunxin.admin.system.infra.framework.resubmit.Resubmit;
//import com.yunxin.admin.system.infra.framework.security.util.SecurityUtils;
//import com.yunxin.admin.system.infra.framework.syslog.AutoLog;
//import com.yunxin.common.exception.BusinessException;
//import com.yunxin.common.result.PageResult;
//import com.yunxin.common.result.Result;
//import com.yunxin.core.application.command.channel.*;
//import com.yunxin.core.application.dto.channel.*;
//import com.yunxin.core.application.service.ChannelApplicationAdminService;
//import com.yunxin.core.application.service.ChannelQueryAdminService;
//import com.yunxin.core.infra.common.channel.enums.ChannelPromtionCustomSwitchStatusEnum;
//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.Parameter;
//import io.swagger.v3.oas.annotations.security.SecurityRequirement;
//import io.swagger.v3.oas.annotations.tags.Tag;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.util.CollectionUtils;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//
///**
// * @author zero°
// * @since 2023-05-30
// */
//@Tag(name = "13.渠道推广管理")
//@Slf4j
//@RestController
//@RequestMapping("/core/v1/channel/promotion")
//@RequiredArgsConstructor
//public class ChannelPromotionController {
//
//    private final ChannelQueryAdminService channelQueryAdminService;
//
//    private final ChannelApplicationAdminService channelApplicationAdminService;
//
//
//    @Operation(summary = "新增渠道推广基础信息", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/addChannelPromotionBasicInfo")
//    @PreAuthorize("@ss.hasPerm('core:channel_promotion:add')")
//    @Resubmit
//    @AutoLog(value = "新增渠道推广基础信息")
//    public Result<Long> addChannelPromotionBasicInfo(@Validated @RequestBody AddChannelPromotionBasicInfoCommand command) {
//        command.setCreator(SecurityUtils.X.getUser().getUsername());
//        return Result.success(channelApplicationAdminService.addChannelPromotionBasicInfo(command));
//    }
//
//    @Operation(summary = "更新渠道推广基础信息", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/updateChannelPromotionBasicInfo")
//    @PreAuthorize("@ss.hasPerm('core:channel_promotion:edit')")
//    @Resubmit
//    @AutoLog(value = "更新渠道推广基础信息")
//    public Result<Boolean> updateChannelPromotionBasicInfo(@Validated @RequestBody UpdateChannelPromotionBasicInfoCommand command) {
//        command.setEditor(SecurityUtils.X.getUser().getUsername());
//        return Result.success(channelApplicationAdminService.updateChannelPromotionBasicInfo(command));
//    }
//
//    @Operation(summary = "获取渠道推广基础信息", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/getChannelPromotionBasicInfo/{promotionId}")
//    public Result<ChannelPromotionBasicInfoDTO> getChannelPromotionBasicInfo(@Parameter(description = "渠道推广id") @PathVariable Long promotionId) {
//        ChannelPromotionBasicInfoDTO result = channelQueryAdminService.getChannelPromotionBasicInfo(promotionId);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "操作渠道推广连接配置（新增/更新）", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/operateChannelPromotionLinkConfig")
//    @Resubmit
//    @AutoLog(value = "操作渠道推广连接配置")
//    public Result<Boolean> operateChannelPromotionLinkConfig(@Validated @RequestBody ChannelPromotionLinkConfigOperateCommand command) {
//        command.setOperator(SecurityUtils.X.getUser().getUsername());
//        return Result.success(channelApplicationAdminService.operateChannelPromotionLinkConfig(command));
//    }
//
//    @Operation(summary = "操作渠道推广客户配置（新增/更新）", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/operateChannelPromotionCustomConfig")
//    @Resubmit
//    @AutoLog(value = "操作渠道推广连接配置")
//    public Result<Boolean> operateChannelPromotionCustomConfig(@Validated @RequestBody ChannelPromotionCustomConfigOperateCommand command) {
//        command.setOperator(SecurityUtils.X.getUser().getUsername());
//        return Result.success(channelApplicationAdminService.operateChannelPromotionCustomConfig(command));
//    }
//
//
//    @Operation(summary = "获取渠道推广连接配置", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/getChannelPromotionLinkConfig/{promotionId}")
//    public Result<ChannelPromotionLinkConfigDTO> getChannelPromotionLinkConfig(@Parameter(description = "渠道推广id") @PathVariable Long promotionId) {
//        ChannelPromotionLinkConfigDTO result = channelQueryAdminService.getChannelPromotionLinkConfig(promotionId);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "操作渠道推广单价配置（新增/更新）", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/operateChannelPromotionUnitPriceConfig")
//    @Resubmit
//    @AutoLog(value = "操作渠道推广单价配置")
//    public Result<Boolean> operateChannelPromotionUnitPriceConfig(@Validated @RequestBody ChannelPromotionUnitPriceConfigOperateCommand command) {
//        command.setOperator(SecurityUtils.X.getUser().getUsername());
//        return Result.success(channelApplicationAdminService.operateChannelPromotionUnitPriceConfig(command));
//    }
//
//    @Operation(summary = "获取渠道推广客户配置", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/getChannelPromotionCustomConfig/{promotionId}")
//    public Result<ChannelPromotionCustomConfigDTO> getChannelPromotionCustomConfig(@Parameter(description = "渠道推广id") @PathVariable Long promotionId) {
//        ChannelPromotionCustomConfigDTO result = channelQueryAdminService.getChannelPromotionCustomConfig(promotionId);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "获取渠道推广单价配置", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/getChannelPromotionUnitPriceConfig/{promotionId}")
//    public Result<ChannelPromotionUnitPriceConfigDTO> getChannelPromotionUnitPriceConfig(@Parameter(description = "渠道推广id") @PathVariable Long promotionId) {
//        ChannelPromotionUnitPriceConfigDTO result = channelQueryAdminService.getChannelPromotionUnitPriceConfig(promotionId);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "更新渠道推广状态", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/updateChannelPromotionStatus")
//    @PreAuthorize("@ss.hasPerm('core:channel_promotion_status:edit')")
//    @Resubmit
//    @AutoLog(value = "更新渠道推广状态")
//    public Result<Boolean> updateChannelPromotionStatus(@Validated @RequestBody UpdateChannelPromotionStatusCommand command) {
//        command.setEditor(SecurityUtils.X.getUser().getUsername());
//        return Result.success(channelApplicationAdminService.updateChannelPromotionStatus(command));
//    }
//
//    @Operation(summary = "分页查询渠道推广列表", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/channelPromotionPageQuery")
//    public PageResult<ChannelPromotionPageDTO> channelPromotionPageQuery(@Validated @RequestBody ChannelPromotionPageCommand command) {
//      return channelQueryAdminService.channelPromotionPageQuery(command);
//    }
//
//    @Operation(summary = "渠道推广结算单价列表", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/listChannelPromotionCharged/{promotionId}")
//    public Result<List<ChannelPromotionChargedListDTO>> listChannelPromotionCharged(@Parameter(description = "渠道推广id") @PathVariable Long promotionId) {
//        List<ChannelPromotionChargedListDTO> result = channelQueryAdminService.listChannelPromotionCharged(promotionId);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "渠道推广关联弹窗", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/relevancePopup")
//    @Resubmit
//    @AutoLog(value = "渠道推广关联弹窗")
//    public Result<Boolean> relevancePopup(@Validated @RequestBody ChannelPopupCommand command) {
//        command.setEditor(SecurityUtils.X.getUser().getUsername());
//        return Result.success(channelApplicationAdminService.relevancePopup(command));
//    }
//
//    @Operation(summary = "查询渠道推广api客户配置", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/getChannelPromotionApiCustomerConfig")
//    public Result<ChannelPromotionApiCustomerConfigDTO> getChannelPromotionCollectConfig(@Parameter(description = "渠道推广code") @RequestParam("promotionCode") String promotionCode) {
//        ChannelPromotionApiCustomerConfigDTO result = channelQueryAdminService.getChannelPromotionApiCustomerConfig(promotionCode);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "操作渠道推广api客户配置（新增/更新）", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/operateChannelPromotionApiCustomerConfig")
//    @Resubmit
//    @AutoLog(value = "操作渠道推广采量配置")
//    public Result<Boolean> operateChannelPromotionApiCustomerConfig(@Validated @RequestBody ChannelPromotionApiCustomerConfigOperateCommand command) {
//        //校验属性开启，必须传入对应值
//        checkCustomConfigParam(command.getEducationLeveSwitch(), command.getEducationLevelList());
//        checkCustomConfigParam(command.getSocialSecuritySwitch(), command.getSocialSecurityLevelList());
//        checkCustomConfigParam(command.getAccumulationFundSwitch(), command.getAccumulationFundLevelList());
//        checkCustomConfigParam(command.getSesameSeedQuotaSwitch(), command.getSesameSeedQuotaList());
//        checkCustomConfigParam(command.getCreditCardSwitch(), command.getCreditCardList());
//        checkCustomConfigParam(command.getHouseLevelSwitch(), command.getHouseLevelList());
//        checkCustomConfigParam(command.getVehicleLevelSwitch(), command.getVehicleLevelList());
//        checkCustomConfigParam(command.getInsureSwitch(), command.getInsureList());
//        checkCustomConfigParam(command.getOccupationSwitch(), command.getOccupationList());
//        checkCustomConfigParam(command.getOccupationIncomeSwitch(), command.getOccupationIncomeList());
//        checkCustomConfigParam(command.getJdBtQuotaSwitch(), command.getJdBtQuotaList());
//        checkCustomConfigParam(command.getAntCreditPayQuotaSwitch(), command.getAntCreditPayQuotaList());
//        checkCustomConfigParam(command.getMicroLoanQuotaSwitch(), command.getMicroLoanQuotaList());
//        checkCustomConfigParam(command.getSexSwitch(), command.getSexList());
//        command.setOperator(SecurityUtils.X.getUser().getUsername());
//        return Result.success(channelApplicationAdminService.operateChannelPromotionApiCustomerConfig(command));
//    }
//
//    @Operation(summary = "查询渠道推广商户配置", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/getChannelPromotionMerchantConfig")
//    public Result<ChannelPromotionMerchantConfigDTO> getChannelPromotionMerchantConfig(@Parameter(description = "渠道推广code") @RequestParam("promotionCode") String promotionCode) {
//        ChannelPromotionMerchantConfigDTO result = channelQueryAdminService.getChannelPromotionMerchantConfig(promotionCode);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "操作渠道推广商户配置（新增/更新）", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/operateChannelPromotionMerchantConfig")
//    @Resubmit
//    @AutoLog(value = "操作渠道推广商户配置")
//    public Result<Boolean> operateChannelPromotionMerchantConfig(@Validated @RequestBody ChannelPromotionMerchantConfigOperateCommand command) {
//        return Result.success(channelApplicationAdminService.operateChannelPromotionMerchantConfig(command));
//    }
//
//    /**
//     * 检查渠道api客户配置参数
//     * @param valueSwitch valueSwitch
//     * @param value value
//     */
//    private void checkCustomConfigParam(Integer valueSwitch, List<Integer> value){
//        if (ChannelPromtionCustomSwitchStatusEnum.OPEN.getValue().equals(valueSwitch) && CollectionUtils.isEmpty(value)) {
//            throw new BusinessException(AdminResultCode.PARAM_ERROR);
//        }
//    }
//}
